package com.ws.haungjia.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.web.multipart.MultipartResolver;
import org.springframework.web.multipart.commons.CommonsMultipartResolver;
import org.springframework.web.servlet.ViewResolver;
import org.springframework.web.servlet.config.annotation.DefaultServletHandlerConfigurer;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.web.servlet.view.InternalResourceViewResolver;
@Configuration
@ComponentScan("com.ws.haungjia.controller")
@ComponentScan("com.ws.haungjia.utils")
@EnableWebMvc
public class SpringMvcConfig implements WebMvcConfigurer {
    /**
     * 创建视图解析器
     * @return
     */

    @Bean(name = "viewResolver")
    public ViewResolver viewResolverInit(){
        InternalResourceViewResolver viewResolver=new InternalResourceViewResolver();
        viewResolver.setPrefix("/");//设置前缀
        viewResolver.setSuffix(".jsp");//设置后缀
        return viewResolver;
    }
    @Bean("multipartResolver")  //方法名是multipartResolver 或者bean中配置名字multipartResolver
    public MultipartResolver multipartResolver() {
        CommonsMultipartResolver multipartResolver = new CommonsMultipartResolver();
        multipartResolver.setMaxUploadSize(10000000); //设置上传文件大小最大值
        return multipartResolver;
    }

    /**
     * 启用默认静态资源处理
     * @param configurer
     */

    @Override
    public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
//启用静态处理
        configurer.enable();
    }

}
